#include "define.h"

void merge(int a[], int left, int center, int right);

int merge_sort(int a[], int left, int right)
{
	int center;
	if (left<right){
		center = (left+right)/2;
		merge_sort(a, left, center);
		merge_sort(a, center+1, right);
		merge(a, left, center, right);
	}
}

void merge(int a[], int left, int center, int right) 
{
	int i, j, k; 
	int b[ARRAYSIZE];
	i = left; j = center+1; k = 0;
	while ((i<=center) && (j<=right)){
		if (a[i] <= a[j]) { 
			b[k] = a[i]; 
			i++; 
		}
		else { 
			b[k] = a[j]; 
			j++;
		}
		k++;
/*		print_array(a); */
	}
	while (i<=center) {
		b[k] = a[i]; 
		i++; 
		k++;
//		print_array(a);
	}
	while (j<=right) {
		b[k] = a[j]; 
		j++; 
		k++;
//		print_array(a);
	}
	for (k=left; k<=right; k++){
		a[k] = b[k-left];
//		print_array(a);
	}
}
